// pages/gift/gift.js
const app = getApp()
var api = require('../../../utils/api.js')
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    limit: 20,
    page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.sku_code) {
      this.setData({
        sku_code: options.sku_code
      })
    }
    this.cards();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  cards: function () {
    var that = this;
    api.POST({
      params: {
        limit: that.data.limit,
        page: that.data.page
      },
      url: app.globalData.base_url + 'giftcard/list',
      success: function (res) {
        wx.hideLoading()
        if (res.data.data.list.length > 1) {
          that.setData({
            cardsList: res.data.data.list
          })
        }
      },
      fail: function (fail) {
        wx.hideLoading()
        util.showError("网络错误，请检查网络");
      }
    })
  },

  giftSel: function (e) {
    let id = e.currentTarget.dataset.id;
    let sku_code = this.data.sku_code;
    wx.navigateTo({
      url: '/play/pages/giftSel/giftSel?id=' + id + "&sku_code=" + sku_code,
    })
  }
})